package cn.congzhou.crm.service.impl;

import cn.congzhou.crm.domain.CustomerTraceHistory;
import cn.congzhou.crm.domain.Employee;
import cn.congzhou.crm.mapper.CustomerTraceHistoryMapper;
import cn.congzhou.crm.query.QueryObject;
import cn.congzhou.crm.service.ICustomerTraceHistoryService;
import cn.congzhou.crm.utils.UserContext;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomerTraceHistoryServiceImpl implements ICustomerTraceHistoryService {

    @Autowired
    private CustomerTraceHistoryMapper customerTraceHistoryMapper;

  

    @Override
    public CustomerTraceHistory selectByPrimaryKey(Long id) {
        CustomerTraceHistory entity = customerTraceHistoryMapper.selectByPrimaryKey(id);
        return entity;
    }

    @Override
    public List<CustomerTraceHistory> selectAll() {
        List<CustomerTraceHistory> entity = customerTraceHistoryMapper.selectAll();
        return entity;
    }

//    保存跟进记录
    @Override
    public void saveOrUpdate(CustomerTraceHistory entity) {
        Employee emp = UserContext.getCurrentUser();
        entity.setInputUser(emp);
        if(entity.getId()!=null){
            customerTraceHistoryMapper.updateByPrimaryKey(entity);
        }else {
            customerTraceHistoryMapper.insert(entity);
        }
    }

//    分页查询数据
    @Override
    public PageInfo<CustomerTraceHistory> selectByPage(QueryObject qo) {
//      调用这个类的静态方法处理分页数据
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),"his.trace_time DESC");
        List<CustomerTraceHistory> list = customerTraceHistoryMapper.selectByPage(qo);
//      创建页面信息对象封装起来
        PageInfo<CustomerTraceHistory> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
